#include <QtOpenGL>
#include "sphere.h"
#include <GL/glu.h>

bool isSphere = true;
Sphere::Sphere(MainWindow *mainWindow,const QVector3D& center, QObject *parent):
    Object3D(center, parent)
{

    QDir d("../DojoGL/");

 //   program.addShaderFromSourceFile(QGLShader::Vertex,   d.absolutePath()+"/estrela.vert");
   // program.addShaderFromSourceFile(QGLShader::Fragment, d.absolutePath()+"/estrela.frag");
    //program.link();

   connect(mainWindow, SIGNAL(radioEvent(bool,bool,bool)),
                 this, SLOT(FiguraSelecionada(bool,bool,bool)));

         connect(mainWindow, SIGNAL(colorchoose(int)), this, SLOT(RecebeCor(int)));
}
void Sphere::RecebeCor(int cor){
    if(cor == 0 && isSphere){
        glColor3f(1.0,0.0,0.0);
    }
   else if(cor == 1 && isSphere){glColor3f(0.0,1.0,0.0);}
    else if(cor == 2 && isSphere){glColor3f(0.0,0.0,1.0);}
    //updateGL();
  //  else {glColor3f(1,1,1); }

}

void Sphere::FiguraSelecionada(bool obj1,bool obj2, bool obj3){
    if(obj1){
   isSphere = true;
    }
    if(obj2||obj3){
    isSphere = false;
    }
}
void Sphere::drawGeometry(void)
{
    glScalef(0.5, 0.5, 0.5);

    GLUquadric *quad = gluNewQuadric();

    gluQuadricDrawStyle(quad, GLU_FILL);
    gluQuadricNormals(quad, GLU_SMOOTH);

    gluQuadricTexture(quad, true);

    program.bind();
   gluSphere(quad, 1, 30, 30);

    program.release();
}
